package com.oneday.ashop.core.base.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串处理公共类
 * User:bob.yang
 * Date 2015/7/20 0020
 */
public class StringUtil {

    /**
     * 判断字符串是否为空
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        if(null == str || "".equals(str) || "".equals(str.trim()) || "null".equalsIgnoreCase(str)) {
            return true;
        }
        return false;
    }

    /**
     * 校验手机号码
     * @param telephone
     * @return
     */
    public static boolean checkTelephone(String telephone) {
        Pattern p = Pattern.compile("^(1|[0-9]{10})$");
        Matcher matcher = p.matcher(telephone);
        return matcher.matches();
    }

    /**
     * 校验邮箱
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        Pattern pattern = Pattern.compile("^\\\\s*\\\\w+(?:\\\\.{0,1}[\\\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\\\.[a-zA-Z]+\\\\s*$");
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}
